package com.net.shop.car.manager.api.volley.response.dingdan;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.Dingdan;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.LogUtils;
import com.net.shop.car.manager.utils.StringUtils;

public class DingdanOrderListResponse extends Response {

	private int totalPages;
	private List<Dingdan> dingdans;
	
	public DingdanOrderListResponse() {
		super(Constants.DINGDAN_ORDER_LIST);
	}
	
	@Override
	public String[] getContentTags() {
		return new String[]{"totalpages","orderlist"};
	}
	
	@Override
	public void parseContent(String content, int index) {
		if (index == 0) {
			totalPages = StringUtils.filterIntegerNull(content);
		} else if (index == 1) {
			
			try {
				JSONArray jsonArray = new JSONArray(content);
				dingdans = new ArrayList<Dingdan>();
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					Dingdan dingdan = new Dingdan();
					dingdan.setCreateDate(StringUtils.filterNull(jsonObject.getString("CREATE_DATE")));
					dingdan.setGoodName(StringUtils.filterNull(jsonObject.getString("GOOD_NAME")));
					dingdan.setGoodPrice(StringUtils.filterMoneyNull(jsonObject.getString("ORDER_PRICE")));
					dingdan.setId(StringUtils.filterNull(jsonObject.getString("ID")));
					dingdan.setOrderId(StringUtils.filterNull(jsonObject.getString("ORDER_ID")));
					dingdan.setUseVb(StringUtils.filterLongNull(jsonObject.getString("USE_POINT")));
					dingdan.setUuid(StringUtils.filterNull(jsonObject.getString("ORDER_UUID")));
					dingdans.add(dingdan);
				}
			} catch (Exception e) {
				LogUtils.e(e.getMessage());
			}
		}
	}

	/**
	 * @return the totalPages
	 */
	public int getTotalPages() {
		return totalPages;
	}

	/**
	 * @return the dingdans
	 */
	public List<Dingdan> getDingdans() {
		return dingdans;
	}

}
